import { Menu, Icon } from 'antd';
import React from 'react';

const SubMenu = Menu.SubMenu;
require('../../css/sideNav.css');

export default class SideNav extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            current: '',
            theme: 'deepBlue',
            currentGroup:0
        };
        this.handleClick = this.handleClick.bind(this)
    }
    componentWillReceiveProps(nextProp){
        this.setState({
            user: nextProp.user,
            current: nextProp.current
        })
    }
    handleClick(e) {
        this.setState({
            current: e.key
        },function(){
            this.props._r.push(`/${e.key}`);
            this.props.jump(`${e.key}`);
        });
    }
    renderNavByRole(){
        const user = this.props.user;
        if(!user){
            return 'loading...'
        }else{
            const role = user.user.username;
            if(role === 'systemadmin'){
                return (
                  <Menu
                    key='admin'
                    theme={this.state.theme}
                    onClick={this.handleClick}
                    style={{ width: 220 }}
                    defaultOpenKeys={[]}
                    selectedKeys={[this.state.current]}
                    mode="inline"
                  >
                    <SubMenu key="admin_0" title={<span><Icon type="appstore-o" /><span>影像管理</span></span>}>
                      <Menu.Item key="_admin"><Icon type="bars" />审核影像</Menu.Item>
                    </SubMenu>
	                  <SubMenu key="admin_1" title={<span><Icon type="hdd" /><span>产品订单管理</span></span>}>
                          <Menu.Item key="product"><Icon type="bars" />产品管理</Menu.Item>
		                  <Menu.Item key="consult-manage"><Icon type="bars" />咨询管理</Menu.Item>
		                  <Menu.Item key="order-manage"><Icon type="bars" />打印刻盘</Menu.Item>
	                  </SubMenu>
                    <SubMenu key="admin_2" title={<span><Icon type="team" /><span>用户管理</span></span>}>
                      <Menu.Item key="user-list"><Icon type="bars" />用户列表</Menu.Item>
	                    <Menu.Item key="specialist-list"><Icon type="solution" />专家列表</Menu.Item>
	                    <Menu.Item key="specialist-listunpass"><Icon type="solution" />待审核专家</Menu.Item>
                    </SubMenu>
                    <SubMenu key="admin_3" title={<span><Icon type="tags-o" /><span>角色权限</span></span>}>
                      {/*<Menu.Item key="role-list"><Icon type="bars" />角色管理</Menu.Item>*/}
                      <Menu.Item key="action"><Icon type="bars" />权限管理</Menu.Item>
                      <Menu.Item key="role"><Icon type="bars" />角色管理</Menu.Item>
	                    <Menu.Item key="admin-list"><Icon type="bars" />管理员管理</Menu.Item>
                    </SubMenu>
                    <SubMenu key="admin_4" title={<span><Icon type="message" /><span>意见消息</span></span>}>
                      <Menu.Item key="message-manage"><Icon type="notification" />消息管理</Menu.Item>
                      <Menu.Item key="suggest-manage"><Icon type="message" />反馈意见</Menu.Item>
                    </SubMenu>
                    <SubMenu key="admin_5" title={<span><Icon type="hdd" /><span>数据字典</span></span>}>
                        <Menu.Item key="producttype"><Icon type="bars" />产品类别</Menu.Item>
                        <Menu.Item key="chargetype"><Icon type="bars" />收费类型</Menu.Item>
                        <Menu.Item key="checktype"><Icon type="bars" />检查分类</Menu.Item>
                        <Menu.Item key="criticality"><Icon type="bars" />危重值</Menu.Item>
                        <Menu.Item key="department"><Icon type="bars" />科室</Menu.Item>
                        <Menu.Item key="gender"><Icon type="bars" />性别</Menu.Item>
                        <Menu.Item key="modality"><Icon type="bars" />设备类型</Menu.Item>
                        <Menu.Item key="nationality"><Icon type="bars" />民族</Menu.Item>
                        <Menu.Item key="patienttype"><Icon type="bars" />患者类型/来源</Menu.Item>
                        <Menu.Item key="testresult"><Icon type="bars" />检测结果</Menu.Item>
                        <Menu.Item key="title"><Icon type="bars" />职称</Menu.Item>
                        <Menu.Item key="idtype"><Icon type="bars" />身份证件类别</Menu.Item>
                        <Menu.Item key="region"><Icon type="bars" />区域</Menu.Item>
                    </SubMenu>
                    <SubMenu key="admin_6" title={<span><Icon type="desktop" /><span>系统管理</span></span>}>
                      <Menu.Item key="system-setting"><Icon type="setting" />系统设置</Menu.Item>
                      <Menu.Item key="logger-manage"><Icon type="book" />日志管理</Menu.Item>
                      <Menu.Item key="template-manage"><Icon type="copy" />报告模板管理</Menu.Item>
                      <Menu.Item key="app-manage"><Icon type="mobile" />App管理</Menu.Item>
                    </SubMenu>
                  </Menu>
                )
            }else{
                return (
                  <Menu
                    key="user"
                    theme={this.state.theme}
                    onClick={this.handleClick}
                    style={{ width: 240 }}
                    defaultOpenKeys={['sub1','sub2','sub3']}
                    selectedKeys={[this.state.current]}
                    mode="inline"
                  >
                    <SubMenu key="sub1" title={<span><Icon type="appstore-o" /><span>影像管理</span></span>}>
                      <Menu.Item key="images"><Icon type="bars" />我的影像</Menu.Item>
                      <Menu.Item key="image-add"><Icon type="plus" />添加新的影像</Menu.Item>
                    </SubMenu>
                    <SubMenu key="sub2" title={<span><Icon type="team" /><span>亲友管理</span></span>}>
                      <Menu.Item key="patients"><Icon type="bars" />亲友列表</Menu.Item>
                      <Menu.Item key="patient-add"><Icon type="plus" />添加新的亲友</Menu.Item>
                    </SubMenu>
                  </Menu>
                )
            }
        }
    }
    render(){
        const _s = this.renderNavByRole();
        return <div>{_s}</div>
    }
}